home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Technical.Notes / Misc / TN.MISC.010 < prev    next >
Encoding:
Text File  |  1990-01-23  |  7.4 KB  |  143 lines  |  [TEXT/pdos]

  1. Apple II
  2. Technical Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6.  
  7. Apple II Miscellaneous
  8. #10:    80-Column GetChar Routine
  9.  
  10. Revised by:    Dave Lyons                                      September 1989
  11. Written by:    Cameron Birse                                    December 1986
  12.  
  13. This Technical Note presents an 80-column GetChar routine.
  14. Changes since November 1988:  Added discussion of single-character input 
  15. on the unenhanced Apple IIe.
  16. _____________________________________________________________________________
  17.  
  18. The following is an example of how to display a string on the 80-column 
  19. screen, reposition the cursor at the beginning of the string, and use the 
  20. right arrow to get characters which are already there or accept new characters 
  21. in their place.  The routine is a simple BASIC program which displays the 
  22. string and repositions the cursor before getting incoming characters.  If the 
  23. character input is a right arrow, the program calls the assembly language 
  24. routine to get the character from screen memory at the current cursor 
  25. location.
  26.  
  27. 10  PRINT  CHR$ (4);"bload getchar.0": REM  first install assembly routine
  28. 20  B$ = "hello"
  29. 30  PRINT  CHR$ (4);"pr#3"
  30. 40  PRINT B$;:B$ = ""
  31. 50  A =  PEEK (1403): REM  get horiz location
  32. 60  A = A - 5: REM  move cursor to beginning of string
  33. 70  POKE 1403,A
  34. 80  GET A$: REM  get a character
  35. 90  IF A$ =  CHR$ (21) THEN  GOSUB 130: REM   if char is forward arrow,
  36.     handle with assembly routine (GETCHAR)
  37. 100  IF A$ =  CHR$ (27) THEN 170: REM   if esc key then we're done
  38. 110  PRINT A$;:B$ = B$ + A$
  39. 120  GOTO 80
  40. 130  CALL 768: REM   GETCHAR
  41. 140  A =  PEEK (6)
  42. 150  A$ =  CHR$ (A)
  43. 160  RETURN 
  44. 170  PRINT : PRINT : PRINT B$: REM  and we're done
  45.  
  46. An assembled listing of the assembly language GetChar routine follows.  It 
  47. works on the Apple IIe and later.
  48.  
  49. SOURCE   FILE #01 =>GETCHAR
  50. ----- NEXT OBJECT FILE NAME IS GETCHAR.0                     
  51. 0300:        0300    1           ORG   $300           
  52. 0300:        C01F    2 RD80VID   EQU   $C01F         ;80 COLUMN STATE
  53. 0300:        C054    3 TXTPAGE1  EQU   $C054         ;TURN OFF PAGE 2 (READ)
  54. 0300:        C055    4 TXTPAGE2  EQU   $C055         ;TURN ON PAGE 2 (READ)
  55. 0300:        C000    5 CLR80COL  EQU   $C000         ;TURN OFF 80 STORE (WRITE)
  56. 0300:        C001    6 SET80COL  EQU   $C001         ;TURN ON 80 STORE (WRITE)
  57. 0300:        0028    7 BASL      EQU   $28           ;BASE ADDRESS OF SCREEN LOCATION
  58. 0300:        0029    8 BASH      EQU   $29
  59. 0300:        057B    9 OURCH     EQU   $57B          ;80 COLUMNS HORIZ. POSITION
  60. 0300:        05FB   10 OURCV     equ   $5fb          ;80 col vertical pos
  61. 0300:        0006   11 char      equ   6             ;place to hand character back to basic
  62. 0300:               12 *
  63. 0300:               13 *************************************************************
  64. 0300:               14 *   GETCHAR - This routine gets an ascii character from the *
  65. 0300:               15 *   80 column display memory of the Apple IIe. It assumes   *
  66. 0300:               16 *   that main memory is switched in and that the base addrs *
  67. 0300:               17 *   of the line has already been calculated and resides     *
  68. 0300:               18 *   in BASL and BASH. It is meant to be called from BASIC   *
  69. 0300:               19 *   as follows:                                             *
  70. 0300:               20 *                     CALL 768                              *
  71. 0300:               21 *                     A = PEEK (6)                          *
  72. 0300:               22 *                     A$ = CHR$(A)                          *
  73. 0300:               23 *   As you can see, the character is returned in location   *
  74. 0300:               24 *   $6 in zero page. This routine is offered as an example. *
  75. 0300:               25 *   No guaranties are made regarding its fitness for any    *
  76. 0300:               26 *   purpose.           By Cameron Birse 6/10/86             *
  77. 0300:               27 *************************************************************
  78. 0300:               28 *
  79. 0300:        0300   29 getchr    equ   *             ;get the char at the current cursor loc.
  80. 0300:A9 01          30           lda   #$01          ;mask for horiz test
  81. 0302:2C 7B 05       31           bit   OURCH         ;are we in main or aux mem?
  82. 0305:D0 17   031E   32           bne   main          ;if bit 0 of OURCH is set, then main mem
  83. 0307:        0307   33 aux       equ   *
  84. 0307:AD 7B 05       34           lda   OURCH         ;get horiz pos.
  85. 030A:18             35           clc                 ;clear the carry for divide
  86. 030B:6A             36           ror   a             ;divide by two
  87. 030C:A8             37           tay                 ;put the result in y
  88. 030D:8D 01 C0       38           sta   SET80COL      ;turn on 80 store
  89. 0310:AD 55 C0       39           lda   TXTPAGE2      ;flip to aux text page
  90. 0313:B1 28          40           lda   (basl),y      ;get the character
  91. 0315:85 06          41           sta   char
  92. 0317:AE 54 C0       42           ldx   TXTPAGE1      ;turn off aux text page
  93. 031A:8D 00 C0       43           sta   CLR80COL      ;turn off 80 store
  94. 031D:60             44           rts
  95. 031E:        031E   45 main      equ   *
  96. 031E:AD 7B 05       46           lda   OURCH         ;get horiz pos.
  97. 0321:18             47           clc                 ;clear the carry for divide
  98. 0322:6A             48           ror   a             ;divide by two
  99. 0323:A8             49           tay                 ;put the result in y
  100. 0324:B1 28          50           lda   (basl),y      ;get the character
  101. 0326:85 06          51           sta   char
  102. 0328:60             52           rts
  103.  
  104.  
  105. Reading a Single Character
  106.  
  107. While the 80-column firmware is active (whether in 40- or 80-column mode), the 
  108. RDKEY routine on the unenhanced Apple IIe unexpectedly allows the user to 
  109. press ESC and move the cursor around the screen the same way RDCHAR does.
  110.  
  111. AppleSoft's GET statement uses RDKEY, so it behaves the same way.  The ESC 
  112. keypress is never returned, so users have problems if you use GET and expect 
  113. them, for example, to press ESC to return to the previous menu.  At this 
  114. point, the cursor turns into an inverse plus sign (+) and your program is 
  115. still waiting for a keypress.  The user presses ESC a few more times, watching 
  116. the cursor alternate between an inverse plus sign and an inverse blank, and 
  117. then turns off the computer in search of a more exciting activity, like 
  118. throwing darts at your disk.
  119.  
  120. If your program can run on the unenhanced IIe, either leave the 80-column 
  121. firmware turned off (PRINT CHR$(21) to make sure it's off), or read keypresses 
  122. by polling the keyboard register directly:
  123.  
  124.     1000 IF PEEK(-16384)<128 THEN 1000     : REM Wait for a keypress
  125.     1010 A$ = CHR$(PEEK(-16384)-128)       : REM Read the key
  126.     1020 POKE -16368,0                     : REM Clear the keyboard strobe
  127.  
  128. or
  129.  
  130.     0300: LDA $C000                ; check for a keypress
  131.     0303: BPL $0300                ;    keep waiting
  132.     0306: AND #$7F                 ; turn off bit 7
  133.     0308: STA $C010                ; clear the keyboard strobe
  134.  
  135. Note that these code fragments don't display a cursor while waiting for a key.
  136.  
  137.  
  138. Further Reference
  139. _____________________________________________________________________________
  140.   o  Apple IIGS Firmware Reference
  141.   o  Apple IIe Technical Reference Manual
  142.   o  Apple IIc Technical Reference Manual, Second Edition
  143.